package fgoScript.exception;

import commons.entity.NativeCp;
import commons.util.GameUtil;
import fgoScript.constant.GameConstant;
import fgoScript.constant.PointInfo;
import mail.mailUtil;

import java.lang.annotation.Native;
import java.text.SimpleDateFormat;
import java.util.Date;

public class AppNeedRestartException extends Exception {
	private static final long serialVersionUID = 1877942104145533378L;
	private String name;
	private static int countError = 0;
	private static long lastThrowMillions= System.currentTimeMillis();

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public AppNeedRestartException() {
		if("RZH_SERVER".equals(NativeCp.getUserName()) && ++countError % 100 == 0){
			String USERNAME = "zmczmckkk@outlook.com";
			String PASSWORD = "Beauty6499!@#";
			mailUtil.sendSMTPMail(USERNAME,PASSWORD,USERNAME,
					"挂机主机异常超过"+countError+"次，异常信息如下："+"\n" + this.getMessage(),"可能出现循环状态！");
		}
	}

	@Override
	public String getMessage() {

		PointInfo.pointInfo = null;
		if(System.currentTimeMillis()-lastThrowMillions > 5 * 1000){
			GameUtil.fullScreen2file(GameConstant.IMG_EXTEND, GameUtil.getPicLogsPath() + "\\ExceptionPic\\" + "AppNeedRestartException" + System.currentTimeMillis() + ".");
		}
		lastThrowMillions=System.currentTimeMillis();
		return "重启模拟器，重新执行脚本！";
	}

	public static void main(String[] args) {
		String USERNAME = "zmczmckkk@outlook.com";
		String PASSWORD = "Beauty6499!@#";
		mailUtil.sendSMTPMail(USERNAME,PASSWORD,USERNAME,
				"挂机主机异常超过"+4+"次，异常信息如下：","可能出现循环状态！");
	}
}
